package cn.com.jtang.wedding.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.jtang.wedding.dao.MessageDao;
import cn.com.jtang.wedding.model.Message;

public class MessageDaoImpl extends BaseDaoImpl implements MessageDao {

	private static final String ID = "id";
	private static final String FROMNUM = "fromNum";
	private static final String CONTENT = "content";
	private static final String USERID = "userId";
	private static final String TIME = "time";
	
	@Override
	public List insertModelToList(Object object) {
		Message message = (Message)object;
		List args = new ArrayList();
		args.add(0);
		args.add(message.getFromNum());	
		args.add(message.getContent());
		args.add(message.getUserId());
		args.add(message.getTime());
		return args;
	}

	@Override
	public Object resultMapper(ResultSet rs, int rowNum) throws SQLException {
		Message message = new Message();
		message.setId(rs.getLong(ID));
		message.setFromNum(rs.getString(FROMNUM));
		message.setContent(rs.getString(CONTENT));
		message.setUserId(rs.getLong(USERID));
		message.setTime(rs.getDate(TIME));
		return message;
	}

	@Override
	public Map updateModelToMap(Object object) {
		Message message = (Message)object;
		Map map = new HashMap();
		map.put(ID, message.getId());
		map.put(FROMNUM, message.getFromNum());
		map.put(CONTENT, message.getContent());
		map.put(USERID, message.getUserId());
		map.put(TIME, message.getTime());
		return map;
	}
	

	public String insert(Message message){
		return super.insert(message);
	}
	
	public Message queryById(Long id){
		return (Message)super.queryById(id);
	}
	
	public int updateById(Long id, Message message) {
		return super.updateById(id, message);
	}
	
	public int deleteById(Long id) {
		return super.deleteById(id);
	}
	
	public List queryAll(Map<String, Object> map, int start,int end, String... orderByStr){
		return super.queryAll(map, start, end, orderByStr);
	}
}
